import React from 'react'
import { Link } from "react-router-dom";
import { Divider,  List, Pagination, BackTop} from 'antd'
import 'antd/dist/antd.css'

import reqwest from 'reqwest';




class Beta extends React.Component {
    state = {
        initLoading: true,
        loading:false,
        current: 1,
        list: [],
        total:0

    };

    onChange = page => {
        console.log(page);
        this.setState({
            loading:true,
            current: page,
        });
        this.getData(page);
        window.scrollTo(0,0);
    };

    componentDidMount() {
        this.getData(1);
    }

    getData = (page) => {
        reqwest({
            url: `https://lessreads.com/renren-admin/api/evaluation/pagelist2?page=${page}&type=2`,
            type: 'json',
            method: 'get',
            contentType: 'application/json',
            success: res => {
                this.setState({
                        initLoading: false,
                        loading: false,
                        data: res.page.list,
                        list: res.page.list,
                        total: res.page.totalCount,
                    }
                );
                console.log(res)
            },
        });
    };

    render() {
        const {initLoading,loading,list}=this.state;
        return (      
            <div> 
                   <div>
                     <List
                        loading={initLoading}
                        className="demo-loadmore-list"
                        itemLayout="horizontal"
                        dataSource={list}
                        renderItem={item => (
                            <List.Item >
                                <div className="content-list">
                                    <div className="content-list-top">
                                        <div className="content-list-img">
                                            <a href={item.recomBookEntity.linkUrl} target="_blank">
                                                <img width="100px" src={item.recomBookEntity.bannerUrl}
                                                        alt={item.recomBookEntity.title}/>
                                            </a>
                                        </div>

                                        <div className="content-list-content">
                                            <p className="recwords" float="left" style={{fontFamily:"tahoma,Arial,PingFang SC,Hiragino Sans GB,Microsoft YaHei,WenQuanYi Micro Hei,sans-serif,TNYAdobeCaslonPro,Times New Roman,Times"}}
                                                rel="noopener noreferrer"
                                                dangerouslySetInnerHTML={{__html: item.content}}>
                                            </p>

                                            <div className="tips">
                                                <span>来自:&nbsp; <span
                                                    className="recomSource">{item.recommandSource}</span></span>
                                                <span>推荐于{item.recommendTime}</span>
                                                <span><a href={item.sourceUrl} target="_blank" >{item.sourceUrl ? "穿越去源地址":""}</a></span>
                                            </div>

                                            <div className="celebrity">
                                                <div  className="personalnametag">
                                                    <span className="personalname" 
                                                    >
                                                    <Link to={ '/recommender/'+item.recomUserEntity.id}  className="white">{item.recomUserEntity.name}</Link>
                                                    </span>
                                                    <span className="font12px">{item.recomUserEntity.tag}</span>
                                                    </div>
                                                <div className="personalurls">                                                               
                                                        {JSON.parse(item.recomUserEntity.siteUrls).map(items=>(
                                                                <span>
                                                                <a className="font12px marginleft10"
                                                                    href={items.url}
                                                                    target="_blank">{items.name}</a>
                                                                    </span>
                                                )
                                                    )}
                                                    </div> 
                                                </div>
                                            
                                        </div>
                                    </div>

                                    <div className="source">
                                        <a href={item.recomBookEntity.linkUrl}
                                                className="book-title">{item.recomBookEntity.title} </a>
                                        <a href={item.recomBookEntity.linkUrl}
                                                className="book-subtitle"> {item.recomBookEntity.subTitle}</a>
                                    </div>
                                </div>
                            
                            </List.Item>
                        )}
                    />
                </div>
                <Divider />
                <Pagination className="pagination center" current={this.state.current} onChange={this.onChange} total={this.state.total}
                            pageSize={20}  hideOnSinglePage={true}/>

       
                    <BackTop />
        
</div>
                
            
        )
    }
}

export default Beta
